#ifndef __ipc_helper_h___
#define __ipc_helper_h___
#include <functional>
#include <memory>
#include <vector>
#include <sys/uio.h>
namespace deliver
{
const char *const UDS_NAME = "/tmp/ipc.deliver"; ///UDS文件名
const char *const USB_DEV = "/dev/video0"; ///usb设备名字
const int port = 10088; ///服务监听端口
} // namespace deliver

struct SEND_PACK {
	std::vector<unsigned char> headbuff; ///buffer
	std::vector<iovec> bufvec; ///发送包 适用于writev
	int aimlen;
};

struct IPC_HELPER {
	static int get_packs(unsigned char *buffhead, int bufflen, void *outbuff[], unsigned int outlen[], int outmax, int *outoffset = nullptr, int *pack_aim_offset = nullptr);

	static int get_packs_all(unsigned char *buffhead, int bufflen, void *outbuff[], unsigned int outlen[], int outmax, int *outmaxoffset = nullptr);

	static int try_get_connected_fd(int &sockfd);
	static int try_get_connected_fd(int &sockfd, const char *ip, int port);
	static int try_get_connected_fd(int &sockfd, const char *paths);

	static int getResolution(int dat[10]);
	static int change_to_channel_socket(int socketfd, int chn);
	static int get_datas(int socketfd, unsigned char *buff, int maxlen, int timout);

	static int simple_read_write_cmd(const char *sndcmd, char *retcmd, int retmaxlen);
	static int set_hdmi_status(int val);
	static int get_hdmi_status(void);
	static int get_usb_info(char *outname, int sz);
	static int get_I_frame(int socket);
	static int get_frame_data(int socket);
	static int set_image_quality(unsigned int frame_rate, unsigned int bit_rate);

/**
 * @brief 强制设置video服务器 ip
 * 
 * @param ip ip地址
 */
	static void set_force_videoserver_ip(const char *);
/**
 * @brief 强制设置video服务器 端口号
 * 
 * @param int 端口号
 */
	static void set_force_videoserver_port(int);

	/**
	 * @brief 数据打包
	 * 
	 * @param frame_addr 地址 
	 * @param frame_size 长度
	 * @param pack_count 包数量
	 * @return std::unique_ptr<SEND_PACK> 
	 */
	static std::unique_ptr<SEND_PACK> make_send_pack(void **frame_addr, size_t *frame_size, int pack_count);
};

void setnonblocking(int sock);
void SetWatchFile(const char *fil, std::function<void(void *priv, const char *fil)> profun, void *priv, std::shared_ptr<int> runningflg);
#endif
